package com.shpng.cheapenglish.persistent;

import java.util.List;

import javax.jdo.PersistenceManager;
import javax.jdo.Query;

import com.shpng.cheapenglish.db.User;

public class UserPersistent {

	private static UserPersistent userPersistent;

	private UserPersistent() {

	}

	public static UserPersistent getInstance() {
		if (userPersistent == null)
			userPersistent = new UserPersistent();
		return userPersistent;
	}

	public void saveUser(User user, PersistenceManager pm) {
		pm.makePersistent(user);
		System.out.println("save user " + user.getEmail());
	}

	@SuppressWarnings("unchecked")
	public List<User> getUsers(PersistenceManager pm) {
		Query query = pm.newQuery(User.class);
		List<User> users = (List<User>) query.execute();
		return users;
	}

}
